home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / mvcsmltn.sit / MVC simulation V3 (HC1) / card_3014.txt < prev    next >
Text File  |  1990-10-26  |  10KB  |  411 lines

  1. -- card: 3014 from stack: in
  2. -- bmap block id: 3178
  3. -- flags: 0000
  4. -- background id: 2806
  5. -- name: 
  6.  
  7.  
  8. -- part 1 (field)
  9. -- low flags: 05
  10. -- high flags: 2004
  11. -- rect: left=95 top=79 right=110 bottom=171
  12. -- title width / last selected line: 0
  13. -- icon id / first selected line: 0 / 0
  14. -- text alignment: 65535
  15. -- font id: 3
  16. -- text size: 18
  17. -- style flags: 256
  18. -- line height: 24
  19. -- part name: Numeric view
  20. ----- HyperTalk script -----
  21. on upDate
  22.   put cd fld "Model" into me
  23. end upDate
  24.  
  25.  
  26. -- part 2 (field)
  27. -- low flags: 05
  28. -- high flags: 0000
  29. -- rect: left=232 top=175 right=193 bottom=262
  30. -- title width / last selected line: 0
  31. -- icon id / first selected line: 0 / 0
  32. -- text alignment: 65535
  33. -- font id: 3
  34. -- text size: 10
  35. -- style flags: 0
  36. -- line height: 13
  37. -- part name: bar feedback
  38. ----- HyperTalk script -----
  39. on feedback X
  40.   if X Γëá empty then
  41.     set style of me to "Rect"
  42.     put (X-left of cd button "bar index") DIV 10 into me
  43.   else
  44.     put empty into me
  45.     set style of me to "Transparent"
  46.   end if
  47. end feedback
  48.  
  49. on newLeft X
  50.   set left of me to X
  51. end newLeft
  52.  
  53.  
  54.  
  55.  
  56.  
  57. -- part 3 (field)
  58. -- low flags: 04
  59. -- high flags: 0000
  60. -- rect: left=325 top=117 right=247 bottom=510
  61. -- title width / last selected line: 0
  62. -- icon id / first selected line: 0 / 0
  63. -- text alignment: 0
  64. -- font id: 3
  65. -- text size: 10
  66. -- style flags: 0
  67. -- line height: 13
  68. -- part name: Dependent views
  69. ----- HyperTalk script -----
  70. on doUpdates
  71.   repeat with i = 1 to number of lines of me
  72.     if line i of me is empty or char 1 of line i of me is "-" then
  73.       next repeat
  74.     end if
  75.     select line i of me
  76.     send "Update" to line i of me
  77.   end repeat
  78. end doUpdates
  79.  
  80.  
  81. -- part 4 (field)
  82. -- low flags: 05
  83. -- high flags: 2000
  84. -- rect: left=434 top=65 right=85 bottom=482
  85. -- title width / last selected line: 0
  86. -- icon id / first selected line: 0 / 0
  87. -- text alignment: 65535
  88. -- font id: 3
  89. -- text size: 10
  90. -- style flags: 256
  91. -- line height: 13
  92. -- part name: Model
  93. ----- HyperTalk script -----
  94. on increment
  95.   add 1 to me
  96.   send "doUpdates" to cd field "Dependent views"
  97. end increment
  98.  
  99. on decrement
  100.   subtract 1 from me
  101.   send "doUpdates" to cd field "Dependent views"
  102. end decrement
  103.  
  104. on setValue n
  105.   if n Γëá me then
  106.     put n into me
  107.     send "doUpdates" to cd field "Dependent views"
  108.   end if
  109. end setValue
  110.  
  111.  
  112.  
  113. -- part 5 (button)
  114. -- low flags: 00
  115. -- high flags: 2002
  116. -- rect: left=180 top=67 right=92 bottom=196
  117. -- title width / last selected line: 0
  118. -- icon id / first selected line: 16692 / 16692
  119. -- text alignment: 1
  120. -- font id: 0
  121. -- text size: 12
  122. -- style flags: 0
  123. -- line height: 16
  124. -- part name: 
  125. ----- HyperTalk script -----
  126. on mouseUp
  127.   send "increment" to cd fld "model"
  128. end mouseUp
  129.  
  130.  
  131. -- part 6 (button)
  132. -- low flags: 00
  133. -- high flags: 2002
  134. -- rect: left=180 top=96 right=120 bottom=196
  135. -- title width / last selected line: 0
  136. -- icon id / first selected line: 3584 / 3584
  137. -- text alignment: 1
  138. -- font id: 0
  139. -- text size: 12
  140. -- style flags: 0
  141. -- line height: 16
  142. -- part name: 
  143. ----- HyperTalk script -----
  144. on mouseUp
  145.   send "decrement" to cd fld model
  146. end mouseUp
  147.  
  148.  
  149. -- part 7 (button)
  150. -- low flags: 00
  151. -- high flags: 2002
  152. -- rect: left=211 top=175 right=198 bottom=233
  153. -- title width / last selected line: 0
  154. -- icon id / first selected line: 26020 / 26020
  155. -- text alignment: 1
  156. -- font id: 0
  157. -- text size: 12
  158. -- style flags: 0
  159. -- line height: 16
  160. -- part name: Bar controller
  161. ----- HyperTalk script -----
  162. on mouseDown
  163.   repeat until the mouse is up
  164.     put item 1 of mouseloc() into X
  165.     newX X
  166.     send "feedback" && X to cd fld "bar feedback"
  167.   end repeat
  168.   send "feedback" to cd fld "bar feedback"
  169.   put (X-left of cd button "bar index") DIV 10 into newVal
  170.   send "SetValue" && newVal to cd fld "Model"
  171. end mouseDown
  172.  
  173. on newX X
  174.   get loc of me
  175.   put X into item 1 of it
  176.   set loc of me to it
  177.   send "newLeft" && right of me-1 to cd fld "bar feedback"
  178. end newX
  179.  
  180.  
  181. -- part 8 (button)
  182. -- low flags: 00
  183. -- high flags: 4001
  184. -- rect: left=132 top=153 right=170 bottom=222
  185. -- title width / last selected line: 0
  186. -- icon id / first selected line: 0 / 0
  187. -- text alignment: 1
  188. -- font id: 0
  189. -- text size: 12
  190. -- style flags: 0
  191. -- line height: 16
  192. -- part name: bar view
  193. ----- HyperTalk script -----
  194. on UpDate
  195.   put card field "Model" into counterValue
  196.   set width of me to abs(10*counterValue)
  197.   if counterValue ΓëÑ 0 then
  198.     set left of me to left of cd button "Bar index"
  199.     send "newX" && right of me to cd button "Bar Controller"
  200.   else
  201.     set right of me to left of cd button "Bar index"
  202.     send "newX" && left of me to cd button "Bar Controller"
  203.   end if
  204. end UpDate
  205.  
  206.  
  207.  
  208. -- part 9 (button)
  209. -- low flags: 00
  210. -- high flags: 4000
  211. -- rect: left=132 top=176 right=194 bottom=133
  212. -- title width / last selected line: 0
  213. -- icon id / first selected line: 0 / 0
  214. -- text alignment: 1
  215. -- font id: 0
  216. -- text size: 12
  217. -- style flags: 0
  218. -- line height: 16
  219. -- part name: Bar index
  220.  
  221.  
  222. -- part 10 (button)
  223. -- low flags: 00
  224. -- high flags: 0003
  225. -- rect: left=127 top=278 right=290 bottom=139
  226. -- title width / last selected line: 0
  227. -- icon id / first selected line: 0 / 0
  228. -- text alignment: 1
  229. -- font id: 0
  230. -- text size: 12
  231. -- style flags: 0
  232. -- line height: 16
  233. -- part name: dial view
  234. ----- HyperTalk script -----
  235. on upDate
  236.   set cursor to busy
  237.   lock Screen
  238.   put (4*(cd field "Model")-90)/180*3.142 into A
  239.   put item 1 of loc of me into x
  240.   put item 2 of loc of me into y
  241.   choose select tool
  242.   drag from x-52, y-52 to x+52, y+52
  243.   domenu "Clear picture"
  244.   choose line tool
  245.   set linesize to 2
  246.   drag from x,y to trunc(x+50*cos(A)),trunc(y+50*sin(A))
  247.   choose browse tool
  248. end upDate
  249.  
  250.  
  251. -- part 11 (button)
  252. -- low flags: 00
  253. -- high flags: 8002
  254. -- rect: left=199 top=227 right=251 bottom=310
  255. -- title width / last selected line: 0
  256. -- icon id / first selected line: 0 / 0
  257. -- text alignment: 1
  258. -- font id: 0
  259. -- text size: 12
  260. -- style flags: 0
  261. -- line height: 16
  262. -- part name: Dice view
  263. ----- HyperTalk script -----
  264. on Update
  265.   put abs(card field "model") into counterValue
  266.   if counterValue Γëñ 12 then
  267.     get (counterValue div 2)
  268.     put rand(it, min(countervalue-1,6)) into Die1
  269.     put counterValue-Die1 into Die2
  270.     set the icon of card button "Die 1" to "Dice,"&Die1
  271.     set the icon of card button "Die 2" to "Dice,"&Die2
  272.   else
  273.     set the icon of card button "Die 1" to empty
  274.     set the icon of card button "Die 2" to empty
  275.   end if
  276.   get card field "model" < 0
  277.   set hilite of card button "Die 1" to it
  278.   set hilite of card button "Die 2" to it
  279. end Update
  280.  
  281. function rand i,j
  282. -- returns a random integer in the interval i to j
  283. return random(j-i+1)-1+i
  284. end rand
  285.  
  286.  
  287.  
  288. -- part 12 (button)
  289. -- low flags: 00
  290. -- high flags: 0000
  291. -- rect: left=211 top=260 right=295 bottom=246
  292. -- title width / last selected line: 0
  293. -- icon id / first selected line: 2104 / 2104
  294. -- text alignment: 1
  295. -- font id: 0
  296. -- text size: 12
  297. -- style flags: 0
  298. -- line height: 16
  299. -- part name: Die 1
  300.  
  301.  
  302. -- part 13 (button)
  303. -- low flags: 00
  304. -- high flags: 0000
  305. -- rect: left=260 top=260 right=295 bottom=295
  306. -- title width / last selected line: 0
  307. -- icon id / first selected line: 2105 / 2105
  308. -- text alignment: 1
  309. -- font id: 0
  310. -- text size: 12
  311. -- style flags: 0
  312. -- line height: 16
  313. -- part name: Die 2
  314.  
  315.  
  316. -- part 14 (button)
  317. -- low flags: 00
  318. -- high flags: A003
  319. -- rect: left=201 top=306 right=328 bottom=309
  320. -- title width / last selected line: 0
  321. -- icon id / first selected line: 0 / 0
  322. -- text alignment: 1
  323. -- font id: 0
  324. -- text size: 12
  325. -- style flags: 0
  326. -- line height: 16
  327. -- part name: Roll
  328. ----- HyperTalk script -----
  329. on mouseUp
  330.   send "setValue" && random(24)-12 to cd fld "model"
  331. end mouseUp
  332.  
  333.  
  334. -- part 16 (field)
  335. -- low flags: 01
  336. -- high flags: 2004
  337. -- rect: left=98 top=0 right=321 bottom=458
  338. -- title width / last selected line: 0
  339. -- icon id / first selected line: 0 / 0
  340. -- text alignment: 0
  341. -- font id: 3
  342. -- text size: 10
  343. -- style flags: 0
  344. -- line height: 13
  345. -- part name: Help
  346. ----- HyperTalk script -----
  347. on mouseUp
  348.   send "mouseUp" to cd button "Help"
  349. end mouseUp
  350.  
  351.  
  352. -- part 17 (button)
  353. -- low flags: 00
  354. -- high flags: 6001
  355. -- rect: left=6 top=5 right=27 bottom=29
  356. -- title width / last selected line: 0
  357. -- icon id / first selected line: 25002 / 25002
  358. -- text alignment: 1
  359. -- font id: 0
  360. -- text size: 12
  361. -- style flags: 0
  362. -- line height: 16
  363. -- part name: Help
  364. ----- HyperTalk script -----
  365. on mouseUp
  366.   if visible of cd fld "Help" then
  367.     hide cd fld help
  368.     set hilite of me to false
  369.   else
  370.     show cd fld help
  371.     set hilite of me to true
  372.   end if
  373. end mouseUp
  374.  
  375.  
  376. -- part contents for card part 4
  377. ----- text -----
  378. 9
  379.  
  380. -- part contents for card part 3
  381. ----- text -----
  382. card button "Dice view"
  383. card field "Numeric view"
  384. card button "Bar view"
  385. card button "Dial view"
  386.  
  387. -- part contents for card part 1
  388. ----- text -----
  389. 9
  390.  
  391. -- part contents for card part 16
  392. ----- text -----
  393. MVC Simulation v3 (HC1 version)
  394. George Coulouris, October 1990
  395. (george@cs.qmw.ac.uk)
  396.  
  397. A simulation of a Counter with multiple views implemented according to the Model-View-Controller paradigm.
  398.  
  399. There are four views:
  400. ΓÇó the Numeric View shows the counter value in numeric form
  401. ΓÇó the Bar View indicates the value and sign of the counter value by the length of a bar
  402. ΓÇó the dial view indicates the counter value by the angle of the 'needle'
  403. ΓÇó the dice view (thanks to Kostas Karlis for this nice idea)!
  404.  
  405. There are four controllers:
  406. ΓÇó  the arrows beside the numeric view (click them)
  407. ΓÇó the arrow below the bar view (drag it)
  408. ΓÇó the "Roll" button gives the counter a random value.
  409.  
  410. Open the script of an object to see its behaviour.  
  411. The scripts correspond as closely as possible to the behaviour of MVC described in the paper.